package com.baseDemo.web.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baseDemo.web.entity.NavigationEntity;
import com.baseDemo.web.service.navigation.NavigationService;

@Controller
@RequestMapping(value="/navigation" ,produces="application/json;charset=UTF-8")
public class NavigationController {
	@Resource NavigationService navigationService;
	
	/**
	 * 获取右侧导航,需要根据用户过滤
	 * @RequestMapping(value="/getNavigation/{rootid}") 
	 * @PathVariable String rootid
	 * @param node
	 * @return
	 */
	@RequestMapping(value="/getNavigation") 
	@ResponseBody
	public NavigationEntity getNavigation(@RequestParam String node,HttpServletRequest request){
		//NavigationEntity navigationEntity = navigationService.getNavigationEntityById(node);
		return navigationService.getNavigationMenu(node, request);
	}
	/**
	 * 获取所有导航信息
	 * @RequestMapping(value="/getNavigation/{rootid}") 
	 * @PathVariable String rootid
	 * @param node
	 * @return
	 */
	@RequestMapping(value="/getAllNavigation") 
	@ResponseBody
	public NavigationEntity getAllNavigation(@RequestParam String node){
		return navigationService.getNavigationEntityById(node);
	}
	/**
	 * 修改/添加导航信息
	 * @param navigationEntity
	 * @return
	 */
	@RequestMapping(value="/updateNavigation") 
	@ResponseBody
/*	public String updateNavigation(@RequestParam String jsonData){
		System.out.println(jsonData);
		Gson gson = new Gson();
		NavigationEntity na = gson.fromJson(jsonData, NavigationEntity.class);
		System.out.println(na.getParentNode());
		return "";
	}*/
	public String updateNavigation(@RequestBody NavigationEntity navigationEntity){
		return navigationService.updateNav(navigationEntity);
	}
	/**
	 * 修改/添加导航信息
	 * @param navigationEntity
	 * @return
	 */
	@RequestMapping(value="/addNavigation") 
	@ResponseBody
	public String addNavigation(@RequestBody NavigationEntity navigationEntity){
		return "{'id':'"+navigationService.save(navigationEntity)+"'}";
	}
	
	/**
	 * 删除导航
	 * @param navigationEntity
	 * @return
	 */
	@RequestMapping(value="/destroyNavigation") 
	@ResponseBody
	public String destroyNavigation(@RequestBody NavigationEntity navigationEntity){
		return navigationService.delete(navigationEntity);
	}
}
